package com.oss.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.oss.common.BaseResponse;
import com.oss.dto.dictionary.*;
import com.oss.entity.system.Dictionary;
import com.oss.service.system.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author chengqiang
 */
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {
    @Autowired
    DictionaryService dictionaryService;

    /**
     * 添加字典
     * @param dto 入参
     * @return 返回提示信息
     */
    @RequestMapping("/addDictionary")
    public BaseResponse<String> addDictionary(@RequestBody @Valid DictionaryAddDto dto){
        return dictionaryService.addDictionary(dto);
    }
    /**
     * 删除字典
     * @param dto 入参
     * @return 返回提示信息
     */
    @RequestMapping("/deleteDictionary")
    public BaseResponse<String> deleteDictionary(@RequestBody @Valid DictionaryDeleteDto dto){
        return BaseResponse.success(dictionaryService.deleteDictionary(dto));
    }
    /**
     * 修改字典
     * @param dto 入参
     * @return 返回提示信息
     */
    @RequestMapping("/updateDictionary")
    public BaseResponse<String> updateDictionary(@RequestBody @Valid DictionaryUpdateDto dto){
        return dictionaryService.updateDictionary(dto);
    }
    /**
     * 获取字典详情
     * @param dto 入参
     * @return 返回提示信息
     */
    @RequestMapping("/getDictionaryById")
    public BaseResponse<Dictionary> getDictionaryById(@RequestBody @Valid GetOneDictionaryDto dto){
        return BaseResponse.success(dictionaryService.getById(dto.getDicId()));
    }
    /**
     * 字典分页
     * @param dto 入参
     * @return 返回提示信息
     */
    @RequestMapping("/selectByPage")
    public BaseResponse<IPage<Dictionary>> selectByPage(@RequestBody @Valid DictionaryPageDto dto){
        return BaseResponse.success(dictionaryService.selectByPage(dto));
    }

    /**
     * 根据字典类型,获取字典列表
     * @param dto 入参
     * @return 返回列表
     */
    @RequestMapping("/selectDictionaryByTypeCode")
    public BaseResponse<List<Dictionary>> selectDictionaryByTypeCode(@RequestBody @Valid SelectDictionaryByTypeDto dto){
        return BaseResponse.success(dictionaryService.selectDictionaryByTypeCode(dto));
    }
    /**
     * 根据字典类型数组,获取字典列表(用于一个页面初始化时,同事查询多个字典类型列表)
     * @param dto 入参
     * @return 返回列表 key=字典code , value=字典列表
     */
    @RequestMapping("/selectDictionaryByTypeCodeSet")
    public BaseResponse<Map<String,List<Dictionary>>> selectDictionaryByTypeCodeSet(@RequestBody @Valid SelectDictionaryByTypeSetDto dto){
        return BaseResponse.success(dictionaryService.selectDictionaryByTypeCodeSet(dto));
    }


}
